/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Dao;

import Entity.LopSHEntity;
import Entity.ketqua;
import Util.ConSQL;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author AnhPhuong
 */
public class LopSHDao {

    public ArrayList<LopSHEntity> selectAll() {
        LopSHEntity lopsh;
        ArrayList<LopSHEntity> list = new ArrayList<LopSHEntity>();
        try {

            String sql = "select * from lopSH";
            CallableStatement cs = ConSQL.getCon().prepareCall(sql);
            cs = ConSQL.getCon().prepareCall(sql);
            ResultSet rs = cs.executeQuery();
            while (rs.next()) {
                lopsh = new LopSHEntity();
                lopsh.setMaLopSH(rs.getString("malopSH"));
                lopsh.setTenLopSH(rs.getString("malopSH"));
                lopsh.setMaKhoa(rs.getString("malopSH"));
                lopsh.setMaNK(rs.getString("maNK"));

                list.add(lopsh);
            }
        } catch (SQLException ex) {
            Logger.getLogger(LopSHDao.class.getName()).log(Level.SEVERE, null, ex);
        }
        return list;
    }

    public boolean update(LopSHEntity lopsh) {
        try {
            PreparedStatement ps = ConSQL.getCon().prepareStatement("update account set malopSH=?, malopSH=?, malopSH=?, maNK=?");

            ps.setString(1,lopsh.getMaLopSH());
            ps.setString(2,lopsh.getTenLopSH());
            ps.setString(3, lopsh.getMaKhoa());
            ps.setString(4, lopsh.getMaNK());
            return (ps.executeUpdate() == 1);
        } catch (SQLException ex) {
            Logger.getLogger(LopSHDao.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    public boolean delete(LopSHEntity lopsh) {
        try {
            String sql = "delete from lopSH where malopSH = ? ";
            CallableStatement pst = ConSQL.getCon().prepareCall(sql);
            pst.setString(1, lopsh.getMaLopSH());
            return (pst.executeUpdate() == 1);
        } catch (SQLException ex) {
            Logger.getLogger(LopSHDao.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
}
